package com.ziyucoding.springboot.labs.lab8.skywalking.rocketmqdemo.producer;

import com.ziyucoding.springboot.labs.lab8.skywalking.rocketmqdemo.message.DemoMessage;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 生产者
 *
 * @author ziyucoding
 * @date 2022-11-01
 **/
@Component
public class DemoProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 同步发送消息
     *
     * @param id
     * @return SendResult
     **/
    public SendResult syncSend(Integer id) {
        // 创建消息
        DemoMessage message = new DemoMessage();
        message.setId(id);
        // 同步发送消息
        SendResult result = rocketMQTemplate.syncSend(DemoMessage.TOPIC, message);
        return result;
    }
}
